package com.learn.project.plan.service.impl;

import com.learn.project.plan.bean.LearnPlanFactory;
import com.learn.project.plan.bean.LearnTask;
import com.learn.project.plan.bean.Plan;
import com.learn.project.plan.bean.PlanFactory;
import com.learn.project.plan.service.LearnPlanService;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * @Description: 学习计划接口实现类
 * @Author: chenfuyuan
 * @Date: 2021/4/27 20:10
 */
public class LearnPlanServiceImpl implements LearnPlanService {
    @Override
    public Plan getPlan() throws IOException, ClassNotFoundException {
        PlanFactory planFactory = new LearnPlanFactory();
        return planFactory.getPlan();
    }

    @Override
    public void savePlan(Plan plan) throws IOException {
        File file = LearnTask.FILE;
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file));
        objectOutputStream.writeObject(plan);
    }
}
